from flask import Flask,session

from datetime import timedelta

app = Flask(__name__)

app.secret_key = 'asfsfafsf'
app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(days=7) #设置session的有效期7天

@app.route('/')
def index():
    return "Hello"

@app.route('/set_session/')
def set_session():
    #设置session的持久化,默认是31天
    session.permanent = True
    #设置session信息
    session['uname'] = 'itbaizhan'
    return '设置session信息'

if __name__ == '__main__':
    app.run(debug=True)